import {JSBridge} from "../JSBridge";
import LoginBase from "../LoginBase";

export default class OppoLogin extends LoginBase {
    
    /**
     * 登录
     * @param onFinish 成功获取用户信息返回参数true,否则false
     */
    login(onFinish: Function) {
        super.login(onFinish);
        this.onLoginFinish = onFinish;
        let qg = JSBridge.getQGObj();
        if (!qg) return;
        let _this = this;
        qg.login({
            force: true,//先尝试拉取登录框
            success(res) {
                console.log(`OPPO登录成功 ${res.data}`);
                _this.session = JSON.stringify(res.data);
                _this.isLogined = true;
                if (_this.onLoginFinish) {
                    _this.onLoginFinish(true);
                }
            },
            fail(res) {
                console.log(`OPPO登录失败 ${res.data}`);
                if (_this.onLoginFinish) {
                    _this.onLoginFinish(false);
                }
            }
        });
    }
}
